/*
 * 部门员工信息
 */
var url = '', jsonData = '';
$(function(){
	loadData();
});

function loadData(){
	loadTopCSS();
	/**
	 * 部门员工信息
	 */
	loadDepartmentEmployeeInformation();
	 
}

function loadTopCSS() {
	$("#li11").addClass("navdown");
}

/**
 * 部门员工信息
 */
function loadDepartmentEmployeeInformation(){
	url = ctx + '/talentInformationController/talentInformation';
	var departmentId = $('#departmentId').val();
	//jsonData = {departmentId:departmentId};
	var pageNum = "0";
	
	jsonData = {departmentId:departmentId,pageNum:pageNum};
	var  returnData= commonAjax();
	
	tbodyHtml = initDepartmentEmployeeInformationHtml(returnData.data);
	$('#departmentEmployeeInformation_tbody').html(tbodyHtml);
	
	/*
	 * 分页数据设置
	 */
	$('#previousDepartmentEmployeeInformationInput').val(returnData.prePage);
	$('#nextDepartmentEmployeeInformationInput').val(returnData.nextPage);
	$('#lastDepartmentEmployeeInformationInput').val(returnData.lastPage);
	
	$('#curPageDepartmentEmployeeInformation').html(returnData.curPage+1);
	$('#totalNumberDepartmentEmployeeInformation').html(returnData.totalNumber);
	$('#totalPageDepartmentEmployeeInformation').html(returnData.totalPage);
	$('#pageSizeDepartmentEmployeeInformation').html(returnData.pageSize);
	   
	/*
	 * 设置 首页 上一页 无法点击
	 */
	if (returnData.prePage=="-1") {
		$('#firstDepartmentEmployeeInformation').attr("disabled","disabled");
		$('#previousDepartmentEmployeeInformation').attr("disabled","disabled");
	}else {
		$('#firstDepartmentEmployeeInformation').removeAttr("disabled");
		$('#previousDepartmentEmployeeInformation').removeAttr("disabled");
	}
	/*
	 * 下一页 和 尾页 也不能点击
	 */
	if(returnData.nextPage==returnData.totalPage){
		$('#nextDepartmentEmployeeInformation').attr("disabled","disabled");
		$('#lastDepartmentEmployeeInformation').attr("disabled","disabled");
	}else {
		$('#nextDepartmentEmployeeInformation').removeAttr("disabled");
		$('#lastDepartmentEmployeeInformation').removeAttr("disabled");
	}
	
};

function turnSelect() {
	url = ctx + '/talentInformationController/searchTalent';
	var keyWord = $('#employeeSelectInput').val();
	var departmentId = $('#departmentId').val();
	var pageNum = "0";
	
	jsonData = {departmentId:departmentId,keyWord:keyWord,pageNum:pageNum};
	var  returnData= commonAjax();
	
	tbodyHtml = initDepartmentEmployeeInformationHtml(returnData.data);
	$('#departmentEmployeeInformation_tbody').html(tbodyHtml);
	
	/*
	 * 分页数据设置
	 */
	$('#previousDepartmentEmployeeInformationInput').val(returnData.prePage);
	$('#nextDepartmentEmployeeInformationInput').val(returnData.nextPage);
	$('#lastDepartmentEmployeeInformationInput').val(returnData.lastPage);
	
	$('#curPageDepartmentEmployeeInformation').html(returnData.curPage+1);
	$('#totalNumberDepartmentEmployeeInformation').html(returnData.totalNumber);
	$('#totalPageDepartmentEmployeeInformation').html(returnData.totalPage);
	$('#pageSizeDepartmentEmployeeInformation').html(returnData.pageSize);
	
	/*
	 * 设置 首页 上一页 无法点击
	 */
	if (returnData.prePage=="-1") {
		$('#firstDepartmentEmployeeInformation').attr("disabled","disabled");
		$('#previousDepartmentEmployeeInformation').attr("disabled","disabled");
	}else {
		$('#firstDepartmentEmployeeInformation').removeAttr("disabled");
		$('#previousDepartmentEmployeeInformation').removeAttr("disabled");
	}
	/*
	 * 下一页 和 尾页 也不能点击
	 */
	if(returnData.nextPage==returnData.totalPage){
		$('#nextDepartmentEmployeeInformation').attr("disabled","disabled");
		$('#lastDepartmentEmployeeInformation').attr("disabled","disabled");
	}else {
		$('#nextDepartmentEmployeeInformation').removeAttr("disabled");
		$('#lastDepartmentEmployeeInformation').removeAttr("disabled");
	}
	
}

function initDepartmentEmployeeInformationHtml(data){
	var returnHtml = '';
	
	if (data.length == 0)
		returnHtml = '<tr><td colspan="5">暂无数据</td></tr>';
	else
		$.each(data, function(index, item) {
			
			if(item.job_name==null){
				item.job_name=" ";
			}
			
			if(item.contact_information==null){
				item.contact_information=" ";
			}
			
			if(item.graduate_school==null){
				item.graduate_school=" ";
			}
			
			if(item.degree_illustration==null){
				item.degree_illustration=" ";
			}
			
			returnHtml += "<tr>"
				+ "<td title='" +item.department+ "'>" +item.department+ "</td>"
				+ "<td title='" +item.name+ "'>"+item.name+"</td>"
				+ "<td title='" +item.job_number+ "'>" + item.job_number+ "</td>"
				+ "<td title='" +item.gender+ "'>"+ item.gender + "</td>" 
				+ "<td title='" +item.job_name+ "'>"+ item.job_name + "</td>"
				+ "<td title='" +item.degree_illustration+ "'>"+ item.degree_illustration + "</td>"
				+ "<td title='" +item.contact_information+ "'>"+ item.contact_information + "</td>"
				+ "<td title='" +item.graduate_school+ "'>"+ item.graduate_school + "</td>"
				+ "<td title='" +item.entry_location+ "'>"+ item.entry_location + "</td>"
				//+ "<td><a href='/employeePage'>查看</a></td></tr>'";
				+ "<td><a href='employeeDetailsController/talentInformationDetails?jobNumber="+item.job_number+"'>查看</a></td></tr>'";
			
		});
	
	
	return returnHtml;
}


/**
 * 部门员工信息 分页功能-----------------------------------
 */
/*
 * 部门员工信息    首页按钮
 */
function firstDepartmentEmployeeInformation(){
	url = ctx + '/talentInformationController/talentInformation';
	
	var departmentId = $('#departmentId').val();
	var pageNum=0;
	jsonData = {departmentId:departmentId,pageNum:pageNum};
	var  returnData= commonAjax();
	
	tbodyHtml = initDepartmentEmployeeInformationHtml(returnData.data);
	$('#departmentEmployeeInformation_tbody').html(tbodyHtml);
	
	/*
	 * 设置 上下页的隐藏域  值
	 */
	$('#previousDepartmentEmployeeInformationInput').val(returnData.prePage);
	$('#nextDepartmentEmployeeInformationInput').val(returnData.nextPage);
	
	$('#curPageDepartmentEmployeeInformation').html(returnData.curPage+1);
	$('#totalNumberDepartmentEmployeeInformation').html(returnData.totalNumber);
	$('#totalPageDepartmentEmployeeInformation').html(returnData.totalPage);
	
	/*
	 * 设置 首页 上一页 无法点击
	 */
	if (returnData.prePage=="-1") {
		$('#firstDepartmentEmployeeInformation').attr("disabled","disabled");
		$('#previousDepartmentEmployeeInformation').attr("disabled","disabled");
	}else {
		$('#firstDepartmentEmployeeInformation').removeAttr("disabled");
		$('#previousDepartmentEmployeeInformation').removeAttr("disabled");
	}
	/*
	 * 下一页 和 尾页 也不能点击
	 */
	if(returnData.nextPage==returnData.totalPage){
		$('#nextDepartmentEmployeeInformation').attr("disabled","disabled");
		$('#lastDepartmentEmployeeInformation').attr("disabled","disabled");
	}else {
		$('#nextDepartmentEmployeeInformation').removeAttr("disabled");
		$('#lastDepartmentEmployeeInformation').removeAttr("disabled");
	}
	
}

/*
 *  部门员工信息 分页功能    上一页按钮
 */
function previousDepartmentEmployeeInformation(){
	url = ctx + '/talentInformationController/talentInformation';
	
	var departmentId = $('#departmentId').val();
	
	var pageNum= $('#previousDepartmentEmployeeInformationInput').val();
	jsonData = {departmentId:departmentId,pageNum:pageNum};
	var  returnData= commonAjax();
	
	tbodyHtml = initDepartmentEmployeeInformationHtml(returnData.data);
	$('#departmentEmployeeInformation_tbody').html(tbodyHtml);
	
	/*
	 * 设置 上下页的隐藏域  值
	 */
	$('#previousDepartmentEmployeeInformationInput').val(returnData.prePage);
	$('#nextDepartmentEmployeeInformationInput').val(returnData.nextPage);
	
	$('#curPageDepartmentEmployeeInformation').html(returnData.curPage+1);
	$('#totalNumberDepartmentEmployeeInformation').html(returnData.totalNumber);
	$('#totalPageDepartmentEmployeeInformation').html(returnData.totalPage);
	
	/*
	 * 设置 首页 上一页 无法点击
	 */
	if (returnData.prePage=="-1") {
		$('#firstDepartmentEmployeeInformation').attr("disabled","disabled");
		$('#previousDepartmentEmployeeInformation').attr("disabled","disabled");
	}else {
		$('#firstDepartmentEmployeeInformation').removeAttr("disabled");
		$('#previousDepartmentEmployeeInformation').removeAttr("disabled");
	}
	/*
	 * 下一页 和 尾页 也不能点击
	 */
	if(returnData.nextPage==returnData.totalPage){
		$('#nextDepartmentEmployeeInformation').attr("disabled","disabled");
		$('#lastDepartmentEmployeeInformation').attr("disabled","disabled");
	}else {
		$('#nextDepartmentEmployeeInformation').removeAttr("disabled");
		$('#lastDepartmentEmployeeInformation').removeAttr("disabled");
	}
	
}

/*
 *  部门员工信息 分页功能    下一页按钮
 */
function nextDepartmentEmployeeInformation(){
	url = ctx + '/talentInformationController/talentInformation';
	
	var departmentId = $('#departmentId').val();
	
	var pageNum= $('#nextDepartmentEmployeeInformationInput').val();
	jsonData = {departmentId:departmentId,pageNum:pageNum};
	var  returnData= commonAjax();
	
	tbodyHtml = initDepartmentEmployeeInformationHtml(returnData.data);
	$('#departmentEmployeeInformation_tbody').html(tbodyHtml);
	
	/*
	 * 设置 上下页的隐藏域  值
	 */
	$('#previousDepartmentEmployeeInformationInput').val(returnData.prePage);
	$('#nextDepartmentEmployeeInformationInput').val(returnData.nextPage);
	
	$('#curPageDepartmentEmployeeInformation').html(returnData.curPage+1);
	$('#totalNumberDepartmentEmployeeInformation').html(returnData.totalNumber);
	$('#totalPageDepartmentEmployeeInformation').html(returnData.totalPage);
	
	/*
	 * 设置 首页 上一页 无法点击
	 */
	if (returnData.prePage=="-1") {
		$('#firstDepartmentEmployeeInformation').attr("disabled","disabled");
		$('#previousDepartmentEmployeeInformation').attr("disabled","disabled");
	}else {
		$('#firstDepartmentEmployeeInformation').removeAttr("disabled");
		$('#previousDepartmentEmployeeInformation').removeAttr("disabled");
	}
	/*
	 * 下一页 和 尾页 也不能点击
	 */
	if(returnData.nextPage==returnData.totalPage){
		$('#nextDepartmentEmployeeInformation').attr("disabled","disabled");
		$('#lastDepartmentEmployeeInformation').attr("disabled","disabled");
	}else {
		$('#nextDepartmentEmployeeInformation').removeAttr("disabled");
		$('#lastDepartmentEmployeeInformation').removeAttr("disabled");
	}
	
}

/*
 *  部门员工信息 分页功能   尾页按钮
 */
function lastDepartmentEmployeeInformation(){
	url = ctx + '/talentInformationController/talentInformation';
	
	var departmentId = $('#departmentId').val();
	
	var pageNum= $('#lastDepartmentEmployeeInformationInput').val();
	jsonData = {departmentId:departmentId,pageNum:pageNum};
	var  returnData= commonAjax();
	
	tbodyHtml = initDepartmentEmployeeInformationHtml(returnData.data);
	$('#departmentEmployeeInformation_tbody').html(tbodyHtml);
	
	/*
	 * 设置 上下页的隐藏域  值
	 */
	$('#previousDepartmentEmployeeInformationInput').val(returnData.prePage);
	$('#nextDepartmentEmployeeInformationInput').val(returnData.nextPage);
	
	$('#curPageDepartmentEmployeeInformation').html(returnData.curPage+1);
	$('#totalNumberDepartmentEmployeeInformation').html(returnData.totalNumber);
	$('#totalPageDepartmentEmployeeInformation').html(returnData.totalPage);
	
	/*
	 * 设置 首页 上一页 无法点击
	 */
	if (returnData.prePage=="-1") {
		$('#firstDepartmentEmployeeInformation').attr("disabled","disabled");
		$('#previousDepartmentEmployeeInformation').attr("disabled","disabled");
	}else {
		$('#firstDepartmentEmployeeInformation').removeAttr("disabled");
		$('#previousDepartmentEmployeeInformation').removeAttr("disabled");
	}
	/*
	 * 下一页 和 尾页 也不能点击
	 */
	if(returnData.nextPage==returnData.totalPage){
		$('#nextDepartmentEmployeeInformation').attr("disabled","disabled");
		$('#lastDepartmentEmployeeInformation').attr("disabled","disabled");
	}else {
		$('#nextDepartmentEmployeeInformation').removeAttr("disabled");
		$('#lastDepartmentEmployeeInformation').removeAttr("disabled");
	}
	
}

function commonAjax(){
	var result = '';
	$.ajax({
		type: 'GET',
		data: jsonData,
	    url: url,
	    async: false,
	    dataType:"json",
	    success: function(data){
	    	result = data;
	    },
	    error: function(){
	    }
	});
	return result;
}
/**
 *  ！！！！！！！！！！！异步请求！！！！！！！！！！！！！
 */
/*function commonAjax(fun, dataType){
	$.ajax({
		type: 'POST',
		data: jsonData,
	    url: url,
	    dataType: dataType,
	    success: function(data){
	    	fun(data);
	    },
	    error: function(){
	    }
	});
}*/